#include "data/entry.h"
#include "files/file.h"
#include "functional/string.h"

namespace Tvimeg
{
	Entry::Entry(const File& file)
		:	files(1, file), commonNameLength(0)
	{
	}

	Entry::~Entry(void)
	{
	}

	void Entry::AddFile(const File& file, const std::size_t commonNameLengthIn)
	{
		files.push_back(file);

		commonNameLength = std::max(commonNameLength, commonNameLengthIn);
	}

	const std::string Entry::GetName(void) const
	{
		if (!files.empty())
		{
			std::string name = files[0].GetName();
			if (commonNameLength > 0)
			{
				return trim(name.substr(0, commonNameLength));
			}
			else
			{
				return name;
			}
		}
		else
		{
			return "";
		}
	}
}
